package pers.julio.notepad.PageSwitcher.Demo;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import pers.julio.notepad.PageSwitcher.Base.BaseFragment;
import pers.julio.notepad.PageSwitcher.Bean.PageAnim;

public class MainFragment extends BaseFragment implements View.OnClickListener {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_main, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.findViewById(R.id.btn1).setOnClickListener(this);
        view.findViewById(R.id.btn2).setOnClickListener(this);
        view.findViewById(R.id.btn3).setOnClickListener(this);
        view.findViewById(R.id.btn4).setOnClickListener(this);
        view.findViewById(R.id.btn5).setOnClickListener(this);
        view.findViewById(R.id.btn6).setOnClickListener(this);
        view.findViewById(R.id.btn7).setOnClickListener(this);
        view.findViewById(R.id.btn8).setOnClickListener(this);
        view.findViewById(R.id.btn9).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn1:
                //int anim[]= {R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right};
                //openPage("test1",null, anim);
                openPage("test1",null, PageAnim.slide);
                break;
            case R.id.btn2:
                openPage("test1",null, PageAnim.none);
                break;
            case R.id.btn3:
                openPage("test1",null, PageAnim.fade,true);
                break;
            case R.id.btn4:
                openPage("test1",null, PageAnim.fade,false);
                break;
            case R.id.btn5:
                openPage("test1",null, PageAnim.fade,true,true);
                break;
            case R.id.btn6:
                int requestCode=1;
                Bundle bundle=new Bundle();
                openPageForResult("test2",bundle, PageAnim.fade,requestCode);
                break;
            case R.id.btn7:
                Bundle params=new Bundle();
                params.putString("test","hello i'm from main");
                openPage("test3", params, PageAnim.slide);
                break;
            case R.id.btn8:
                popToBack();
                break;
            case R.id.btn9:
                openPage("test4",null, PageAnim.present);
                break;
        }
    }

    @Override
    public void onFragmentResult(int requestCode, int resultCode, Intent data) {
        super.onFragmentResult(requestCode, resultCode, data);
        if(data!=null) {
            Bundle extras = data.getExtras();
            Toast.makeText(getActivity(), "requestCode:" + requestCode + " result:" + resultCode+" data:"+extras.getString("data"), Toast.LENGTH_LONG).show();
        }
    }

}
